#ifndef VIDEOWIDGET_H
#define VIDEOWIDGET_H

#include <QWidget>
#include <QUdpSocket>
#include <QTimer>
#include <opencv2/opencv.hpp>

namespace Ui {
class VideoWidget;
}

class VideoWidget : public QWidget
{
    Q_OBJECT
public:
    explicit VideoWidget(QWidget *parent = NULL);
      void setSavePath(const QString &path);  // 用于外部设置路径
    ~VideoWidget();
private slots:
    void readPendingDatagrams();
    void processAndDisplayImage();
    void on_startBtn_clicked();
    void on_stopBtn_clicked();
    void on_saveBtn_clicked();

private:
    Ui::VideoWidget *ui;
    QUdpSocket *udpSocket;
    QHostAddress serverAddress;
    quint16 serverPort;
    cv::CascadeClassifier eyeClassifier;
    cv::CascadeClassifier faceClassifier;
    QTimer *processTimer;
    bool isReceiving;
    bool isStreaming;
    QByteArray imageData;
    QString savePath;  // 声明保存路径变量
    int m_fileIndex;

    // 辅助函数声明
    QString generateRandomFileName();
    void autoSaveImage(const cv::Mat &frame);
};

#endif // WIDGET_H
